
package webui;

import java.util.Date;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;
//import com.sun.rave.web.ui.component.Calendar;
import java.text.SimpleDateFormat;
/**
 *
 * @author OpenCodes
 */
public class FechaValidador implements Validator {

    @Override
    public void validate(FacesContext arg0, UIComponent componente, Object valor) throws ValidatorException {
        String date = (String) valor; //((Calendar) componente).getSubmittedValue();
        try {
            Date dt = converStringToDate(date);
        } catch (Exception ex) {
            ex.printStackTrace();
            //((Calendar) componente).setSubmittedValue("");
            throw new ValidatorException(new FacesMessage("Fecha no valida"));
        }
    }
    public Date converStringToDate(String dateString) {
        SimpleDateFormat sdf;
        sdf= new SimpleDateFormat();
        Date dt = null;
        try {
            dt = sdf.parse(dateString);
        } catch (java.text.ParseException p) {
            System.out.println(p.toString());
        }
        return dt;
    }
}
